/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaModificarEleccion.java
 *
 * Created on 14-may-2012, 13:26:37
 */
package gui;

import ClasesAModificar.*;
import javax.swing.JOptionPane;
import src.Core;
import src.InfoMedianteID;

/**
 *
 * @author usuario_local
 */
public class VentanaModificarEleccion extends javax.swing.JFrame {

    int padre;
    VentanaModificar vm;
    
    /** Creates new form VentanaModificarEleccion */
    public VentanaModificarEleccion(int padre, VentanaModificar vm) {
        this.padre = padre;
        this.vm = vm;
        initComponents();
        switch(padre)
        {
            case 1:
                jTextArea_vanSeleccion.setText(Core.dameTodosDocumentos());
                break;
            case 2:
                jTextArea_vanSeleccion.setText(Core.dameTodosAcontecimientos());
                break;
            case 3:
                jTextArea_vanSeleccion.setText(Core.dameTodosPersonajes());
                break;
            case 4:
                jTextArea_vanSeleccion.setText(Core.dameTodosColectivos());   
                break;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton_vmeModificar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_vanSeleccion = new javax.swing.JTextArea();
        jLabel_vanSeleccion = new javax.swing.JLabel();
        jTextField_VMESeleccion = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jButton_vmeModificar.setText("Modificar");
        jButton_vmeModificar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vmeModificarMouseClicked(evt);
            }
        });

        jTextArea_vanSeleccion.setColumns(20);
        jTextArea_vanSeleccion.setEditable(false);
        jTextArea_vanSeleccion.setRows(5);
        jScrollPane2.setViewportView(jTextArea_vanSeleccion);

        jLabel_vanSeleccion.setText("Indice que desea añadir:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vanSeleccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_VMESeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                        .addComponent(jButton_vmeModificar))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_vmeModificar)
                    .addComponent(jLabel_vanSeleccion)
                    .addComponent(jTextField_VMESeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton_vmeModificarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vmeModificarMouseClicked
// TODO add your handling code here:

        if(!this.jTextArea_vanSeleccion.getText().equals("")) {
            try{
                Integer.parseInt(this.jTextField_VMESeleccion.getText());  
                int elem = Integer.parseInt(jTextField_VMESeleccion.getText());

                switch(padre){
                    case 1:
                        DocumentoModificar DM = InfoMedianteID.dameDocumento(elem);
                        VentanaModificarDocumento vmd = new VentanaModificarDocumento(elem,vm,DM);
                        vmd.setVisible(true);
                        this.setVisible(false);
                        this.dispose();
                        break;
                    case 2:
                        AcontecimientoModificar AM = InfoMedianteID.dameAcontecimiento(elem);
                        VentanaModificarAcontecimiento vma = new VentanaModificarAcontecimiento(elem,vm,AM); 
                        vma.setVisible(true);
                        this.setVisible(false);
                        this.dispose();
                        break;
                    case 3:
                        PersonajeMoficar PM = InfoMedianteID.damePersonaje(elem);
                        VentanaModificarPersonaje vmp = new VentanaModificarPersonaje(elem, vm,PM);
                        vmp.setVisible(true);
                        this.setVisible(false);
                        this.dispose();
                        break;
                    case 4:
                        ColectivoModificar CM = InfoMedianteID.dameColectivo(elem);
                        VentanaModificarColectivo vmc = new VentanaModificarColectivo(elem, vm,CM);
                        vmc.setVisible(true);
                        this.setVisible(false);
                        this.dispose();
                        break;
                }
            }catch(Exception e){
                JOptionPane.showMessageDialog(null,e.toString() + "\n\n" + "Por favor introduzca el numero que represente el indice que desea añadir");
            }
    }else{
        vm.setVisible(true);
        this.setVisible(false);
        this.dispose();
        JOptionPane.showMessageDialog(null, "No hay ningun dato disponible para modificar");
    }
}//GEN-LAST:event_jButton_vmeModificarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vmeModificar;
    private javax.swing.JLabel jLabel_vanSeleccion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_vanSeleccion;
    private javax.swing.JTextField jTextField_VMESeleccion;
    // End of variables declaration//GEN-END:variables
}
